<?php
declare (strict_types=1);

namespace app\service;

use app\model\TLabel;
use app\traits\ServiceTrait;
use app\util\JwtUtil;
use app\service\AuthGroupService;
use think\facade\Db;

/**
 * 标签
 * Class TLabelService
 * @package app\service
 */
class TLabelService
{
    //仓库，带命名空间
    public static $repository = 'app\repository\TLabelRepository';

    use ServiceTrait;

    /**
     * @param $field
     * @return array
     */
    public static function getLists($page = 1, $psize = 20, $field = [])
    {
        // 列表
        $table = TLabel::$_table;
        $r = Db::table($table)->group('label_type_id')->field('label_type_id')->select();
        $data = [];
        foreach ($r as $k => $v) {
            $data[$k]['checkValue'] = '';
            $data[$k]['id'] = $v['label_type_id'];
            $labels = Db::table($table)->where('label_type_id', $v['label_type_id'])
                ->field('code,code_name as codeName, id, label_type_id as labelTypeId, label_type_name as labelTypeName, remark')
                ->select();
            $data[$k]['labels'] = $labels->toArray();
        }
        return $data;
    }
}
